package com.ruoyi.business.sundry.domain.vo;

import com.ruoyi.business.sundry.domain.JbPerformance;
import com.ruoyi.common.annotation.Excel;
import lombok.Data;
import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;

@Data
public class JbStatisticsPerformanceVo extends JbPerformance
{
    /**
     * 转化率
     */
    @Getter
    private BigDecimal conversionRate = BigDecimal.ZERO;
    /**
     * 金额
     */
    private BigDecimal totalAmount = BigDecimal.ZERO;
    /**
     * 平均客单价
     */
    private BigDecimal average = BigDecimal.ZERO;
    /**
     * 数量
     */
    private Integer totalCount = 0;
    /**
     * 商品数量
     */
    private Integer commodityCount = 0;
    /**
     * 用户名称
     */
    private String userName;
    /**
     * 部门名称
     */
    private String deptName;
    /**
     * 时间
     */
    private String time;
    /**
     * 排序
     */
    private Integer ranking;


    /**
     * 部门id
     */
    private Long deptId;
    /**
     * 用户id
     */
    private List<Long> userIds;
    /**
     * 新增客户
     */
    @Excel(name = "新增客户")
    private Integer customerAdd=0;
    /**
     * 新增跟进记录
     */
    @Excel(name = "新增跟进")
    private Integer followUpAdd=0;
    /**
     * 新增订单
     */
    @Excel(name = "新增订单")
    private Integer orderAdd=0;


    public void getConversionRateCompute()
    {
        this.setTotalAmount(ObjectUtils.isEmpty(this.getTotalAmount()) ? BigDecimal.ZERO : this.getTotalAmount());
        this.setAnnualTarget(ObjectUtils.isEmpty(this.getAnnualTarget()) ? BigDecimal.ZERO : this.getAnnualTarget());
        if (this.getAnnualTarget().compareTo(BigDecimal.ZERO) == 0)
        {
            this.setConversionRate(new BigDecimal(100));
        } else
        {
            this.setConversionRate(this.getTotalAmount()
                    .divide(this.getAnnualTarget(), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100))
            );
        }
    }
}
